package com.heer.gymnasium.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.heer.gymnasium.R;
import com.heer.model.MineActionBean;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by rzw2 on 2017/4/5.
 */

public class MineFragmentActionAdapter extends ListAdapter<MineActionBean> {
    public MineFragmentActionAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHolder holder;
        if (view != null) {
            holder = (ViewHolder) view.getTag();
        } else {
            view = mInflater.inflate(R.layout.item_mine_fragment, parent, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }

        MineActionBean item = getItem(position);
        if (item.isDivider()) {
            holder.lineCrudeTop.setVisibility(View.GONE);
            holder.lineFineTop.setVisibility(View.GONE);
            holder.lineCrudeBottom.setVisibility(View.VISIBLE);
            holder.lineFineBottom.setVisibility(View.GONE);
        } else {
            holder.lineCrudeTop.setVisibility(View.GONE);
            holder.lineFineTop.setVisibility(View.GONE);
            holder.lineCrudeBottom.setVisibility(View.GONE);
            holder.lineFineBottom.setVisibility(View.VISIBLE);
        }

        holder.tvTitle.setText(item.getTitle());
        return view;
    }

    static class ViewHolder {
        @BindView(R.id.line_fine_top)
        View lineFineTop;
        @BindView(R.id.line_crude_top)
        View lineCrudeTop;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tv_desc)
        TextView tvDesc;
        @BindView(R.id.line_fine_bottom)
        View lineFineBottom;
        @BindView(R.id.line_crude_bottom)
        View lineCrudeBottom;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
